home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 December / PCWDEC07.iso / Software / Shareware / Directory Opus 9.0.0.8 / DOpusInstall.exe / Disk1 / data1.cab / Help_Files / DOpus.chm / doctohelp.js < prev    next >
Encoding:
JavaScript  |  2007-08-30  |  24.6 KB  |  944 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // dhtml functions: require IE4 or later
  4. //
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6.  
  7. var POPUP_COLOR = "LightYellow";
  8. var POPUP_REPEAT = "no-repeat";
  9. var POPUP_IMAGE = "";
  10. var IMAGE_OPEN = "%OpenPictureContentsTopic%";
  11. var IMAGE_CLOSE = "%ClosePictureContentsTopic%";
  12. var INDEX_SELECTED = "%OpenPictureNavigatorIndex%";
  13. var INDEX_UNSELECTED = "%ClosePictureNavigatorIndex%";
  14. var CONTENTS_SELECTED = "%OpenPictureNavigatorContents%";
  15. var CONTENTS_UNSELECTED = "%ClosePictureNavigatorContents%";
  16. var ANCHOR = "";
  17. var _d2hInlinePopup = null;
  18.  
  19. function d2hCreatePopupIFrame(doc)
  20. {
  21.     var nstx = doc.all["nstext"];
  22.     if (nstx == null)
  23.         nstx = doc.body;
  24.     nstx.insertAdjacentHTML("BeforeEnd", "<div id='popupDiv'></div>")
  25.     var div = getElemById(document, "popupDiv");
  26.     if (div == null)
  27.         return null;
  28.     div.innerHTML = "<iframe id=\"popupFrame\" name=\"d2h_popupFrameWnd\" frameborder=\"no\" height=\"0px\" width=\"0px\" style=\"display:none; position: absolute;\"></iframe>";
  29.     var frm = getElemById(doc, "popupFrame");
  30.     if (typeof div.removeNode != "undefined")
  31.         div.removeNode(false);
  32.     frm.style.margin = "0pt";
  33.     frm.style.padding = "0pt";
  34.     return frm;
  35.  
  36. function dhtml_popup(url)
  37. {
  38.     ANCHOR = "";
  39.     var pop, main, body, x, y;
  40.  
  41.     // no url? then hide the popup
  42.     if (url == null || url.length == 0)
  43.     {
  44.         pop = document.all["popupFrame"];
  45.         if (pop != null)
  46.             pop.style.display = "none";
  47.         return;
  48.     }
  49.  
  50.     // if the popup frame is already open, close it first
  51.     var popUpShown = dhtml_popup_is_open();
  52.     if (popUpShown)
  53.     {
  54.         // the main window is the parent of the popup frame
  55.         main = window.parent;
  56.         body = main.document.body;
  57.         pop = main.document.all["popupFrame"];
  58.  
  59.         // add the popup origin to the event coordinates
  60.         x = pop.offsetLeft + window.event.offsetX;
  61.         y = pop.offsetTop + window.event.offsetY;
  62.  
  63.         // hide the popup frame
  64.         pop.style.display = "none";
  65.     }
  66.     else
  67.     {
  68.         // the main window is the current window
  69.         main = window;
  70.         body = document.body;
  71.         pop = document.all["popupFrame"];
  72.  
  73.         // use the event coordinates for positioning the popup
  74.         x = window.event.x;
  75.         y = window.event.y;
  76.         // account for the scrolling text region, if present
  77.         var nstx = document.all["nstext"];
  78.         if (nstx != null)
  79.         {
  80.             if (document.body.scroll == "no")
  81.                 y += nstx.scrollTop - nstx.offsetTop;
  82.         }
  83.         // get the popup frame, creating it if needed
  84.         if (pop == null)
  85.             pop = d2hCreatePopupIFrame(document);
  86.     }
  87.     if (pop == null)
  88.     {
  89.         d2hwindow(url, "d2hPopup");
  90.         return;
  91.     }
  92.  
  93.     // get frame style
  94.     var sty = pop.style;
  95.  
  96.     // load url into frame
  97.     var anchorIndex = url.indexOf("#", 0);
  98.     var strUrl;
  99.     if (anchorIndex >= 0)
  100.     {
  101.         ANCHOR = url.substr(anchorIndex + 1);
  102.         //workaround to reset current src
  103.         strUrl = url.substr(0, anchorIndex);
  104.     }
  105.     else
  106.         strUrl = url;
  107.     if (popUpShown)
  108.         open(strUrl, "d2h_popupFrameWnd");
  109.     else
  110.         pop.setAttribute("src", strUrl);
  111.  
  112.     // initialize frame size/position
  113.     sty.border    = "1px solid #cccccc";
  114.     sty.posLeft   = x + body.scrollLeft     - 30000;
  115.     sty.posTop    = y + body.scrollTop + 15 - 30000;
  116.     var wid       = body.clientWidth;
  117.     sty.posWidth  = (wid > 500)? wid * 0.6: wid - 20;
  118.     sty.posHeight = 0;
  119.  
  120.     // wait until the document is loaded to finish positioning
  121.     main.setTimeout("dhtml_popup_position()", 100);
  122. }
  123.     
  124. function dhtml_popup_is_open()
  125. {
  126.     if (window.name != "")
  127.         return window.name != "right";
  128.     else
  129.         return window.location.href != window.parent.location.href;
  130. }
  131.  
  132. function dhtml_popup_position()
  133. {
  134.     // get frame
  135.     var pop = document.all["popupFrame"];
  136.     var frm = document.frames["popupFrame"];
  137.     var sty = pop.style;
  138.  
  139.     if (frm.document.readyState != "complete")
  140.     {
  141.         window.setTimeout("dhtml_popup_position()", 100);
  142.         return;
  143.     }
  144.  
  145.     if (frm.document.body.all.length == 0)
  146.         //if frame is empty, it contains its document, workaround must be applied
  147.         d2h_set_popup_html(frm.document);
  148.  
  149.     if (ANCHOR != "")
  150.         //for non-splitting mode topics that are not needed must be hidden
  151.         d2h_hide_unused_elements(frm.document);
  152.  
  153.     // get containing element (scrolling text region or document body)
  154.     var body = document.all["nstext"];
  155.     var poptext = frm.document.all["nstext"];
  156.     var nsbanner = frm.document.all["_d2hTitleNavigator"];
  157.     d2hStandardizePopupMargin(frm.document.body, poptext, nsbanner);
  158.     if (body == null)
  159.         body = document.body;
  160.  
  161.     // hide navigation/nonscrolling elements, if present
  162.     dhtml_popup_elements(frm.self.document);
  163.  
  164.     // get content size
  165.     sty.display = "block";
  166.     frm.scrollTo(0,1000);
  167.     sty.posHeight = frm.self.document.body.scrollHeight;
  168.  
  169.     // make content visible
  170.     sty.posLeft  += 30000;
  171.     sty.posTop   += 30000;
  172.  
  173.     // adjust x position
  174.     if (sty.posLeft + sty.posWidth + 10 - body.scrollLeft > body.clientWidth)
  175.         sty.posLeft = body.clientWidth  - sty.posWidth - 10 + body.scrollLeft;
  176.  
  177.     // if the frame fits below the link, we're done
  178.     if (sty.posTop + sty.posHeight - body.scrollTop < body.clientHeight)
  179.         return;
  180.  
  181.     // calculate how much room we have above and below the link
  182.     var space_above = sty.posTop - body.scrollTop;
  183.     var space_below = body.clientHeight - space_above;
  184.     space_above -= 35;
  185.     space_below -= 20;
  186.     if (space_above < 50) space_above = 50;
  187.     if (space_below < 50) space_below = 50;
  188.  
  189.     // if the frame fits above or we have a lot more room there, move it up and be done
  190.     if (sty.posHeight < space_above || space_above > 2 * space_below)
  191.     {
  192.         if (sty.posHeight > space_above)
  193.             sty.posHeight = space_above;
  194.         sty.posTop = sty.posTop - sty.posHeight - 30;
  195.         return;
  196.     }
  197.  
  198.     // adjust frame height to fit below the link
  199.     sty.posHeight = space_below;
  200. }
  201.  
  202. function dhtml_popup_elements(doc)
  203. {
  204.     d2hShowTopicTitleInPopup(doc);
  205.     d2hHideBreadcrumbs(doc);
  206.  
  207.     // set popup background style
  208.     doc.body.style.backgroundColor = POPUP_COLOR;
  209.     doc.body.style.backgroundImage = "url('" + d2hGetRelativePath(doc, POPUP_IMAGE) + "')";
  210.     doc.body.style.backgroundRepeat = POPUP_REPEAT;
  211.  
  212.     // reset background image/color of scrolling text region, if present
  213.     var nstx = doc.all["nstext"];
  214.     if (nstx != null)
  215.     {
  216.         nstx.style.backgroundImage = "none";
  217.         nstx.style.backgroundColor = "transparent";
  218.     }
  219. }
  220.  
  221. function d2hSetTopicTextRightIndent(elem)
  222. {
  223.     if (_needIndentation)
  224.         elem.style.paddingRight = "20px";
  225. }
  226.  
  227. function dhtml_nonscrolling_resize()
  228. {
  229.     if (document.body.clientWidth == 0)
  230.         return;
  231.  
  232.     var oBanner= document.all.item("nsbanner");
  233.     var oText= document.all.item("nstext");
  234.  
  235.     if (oText == null)
  236.         return;
  237.  
  238.     var oTitleRow = document.all.item("TitleRow");
  239.  
  240.     if (oTitleRow != null)
  241.         oTitleRow.style.padding = "4px 10px 4px 22px;";
  242.  
  243.     if (oBanner != null)
  244.     {
  245.         document.body.scroll = "no"
  246.         oText.style.overflow = "auto";
  247.          oBanner.style.width = document.body.clientWidth;
  248.         d2hSetTopicTextRightIndent(oText);
  249.         oText.style.width = document.body.clientWidth;
  250.         oText.style.top = 0;  
  251.  
  252.         if (document.body.offsetHeight > oBanner.offsetHeight + 4)
  253.             oText.style.height = document.body.offsetHeight - oBanner.offsetHeight - 4;
  254.         else
  255.             oText.style.height = 0;
  256.     }    
  257.  
  258. //    try{nstext.setActive();} //allows scrolling from keyboard as soon as page is loaded. Only works in IE 5.5 and above.
  259. //    catch(e){}
  260.  
  261.     d2hRegisterEventHandler(window, document.body, "onresize", "d2hnsresize();");
  262.     d2hRegisterEventHandler(window, document.body, "onbeforeprint", "d2h_before_print();");
  263.     d2hRegisterEventHandler(window, document.body, "onafterprint", "d2h_after_print();");
  264.  
  265. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  266. //
  267. // d2h functions: browser-independent
  268. //
  269. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  270.  
  271. function d2hie()
  272. {
  273.     var ie = navigator.userAgent.toLowerCase().indexOf("msie");
  274.     return ie != -1 && parseInt(navigator.appVersion) >= 4;
  275. }
  276.  
  277. function d2hpopup(url)
  278. {
  279.     if (_d2hInlinePopup != null)
  280.     {
  281.         var elem = (window.event.srcElement) ? window.event.srcElement : null;
  282.         if (elem == null || !d2hElementInContainer(elem, _d2hInlinePopup))
  283.         {
  284.             d2hHideInline(_d2hInlinePopup);
  285.             _d2hInlinePopup = null;
  286.         }
  287.     }
  288.  
  289.     // use dhtml if we can
  290.     if (d2hie())
  291.     {
  292.         dhtml_popup(url);
  293.         return false;
  294.     }
  295.  
  296.     // use regular popups
  297.     if (url != null && url.length > 0)
  298.     {
  299.         var pop = window.open(url, '_d2hpopup', 'resizable=1,toolbar=0,directories=0,status=0,location=0,menubar=0,height=300,width=400');
  300.         pop.focus();                 // if the popup was already open
  301.         pop.onblur = "self.close()"; // doesn't work, not sure why...
  302.     }
  303.  
  304.     // and ignore the click
  305.     return false;
  306. }
  307.  
  308. function d2hwindow(url, name)
  309. {
  310.     if (name != 'main')
  311.     {
  312.         window.open(url, name, 'scrollbars=1,resizable=1,toolbar=0,directories=0,status=0,location=0,menubar=0,height=300,width=400');
  313.         return false;
  314.     }
  315.     return true;
  316. }
  317.  
  318. function d2hcancel(msg, url, line)
  319. {
  320.     return true;
  321. }
  322.  
  323. function d2hload()
  324. {
  325.     window.focus();
  326.     window.onerror = d2hcancel;
  327.     if (window.name == '_d2hpopup')
  328.     {
  329.         var major = parseInt(navigator.appVersion);
  330.         if (major >= 4)
  331.         {
  332.             var agent = navigator.userAgent.toLowerCase();
  333.             if (agent.indexOf("msie") != -1)
  334.                 document.all.item("ienav").style.display = "none";
  335.             else
  336.                 document.layers['nsnav'].visibility = 'hide';
  337.         }
  338.     }
  339. }
  340.  
  341. function d2hframeload()
  342. {
  343.     // for compatibility with HTML generated by earlier versions
  344. }
  345.  
  346. function d2htocload()
  347. {
  348.     if (d2hie())
  349.     {
  350.         var id, elt;
  351.         var count = document.all.length;
  352.  
  353.         for (i = 0; i < count; i++)
  354.         {
  355.             elt = document.all.item(i);
  356.  
  357.             if (elt.id.substring(0, 1) == "c")
  358.                 elt.style.display = "none";
  359.  
  360.             else if (elt.id.substring(0, 2) == "mi")
  361.                 d2himage(elt, IMAGE_CLOSE, "closed.gif");
  362.         }
  363.     }
  364. }
  365.  
  366. function d2hclick()
  367. {
  368.     if (d2hie())
  369.     {
  370.         var id = window.event.srcElement.id;
  371.  
  372.         var n = id.substring(0, 1);
  373.         if (id.substring(0, 1) != "m")
  374.             return;
  375.  
  376.         var sub = id.substring(2);
  377.         var elt = document.all.item("c" + sub);
  378.         var img = document.all.item("mi" + sub);
  379.  
  380.         if (elt != null)
  381.         {
  382.             if (elt.style.display == "none")
  383.             {
  384.                 elt.style.display = "";
  385.                 d2himage(img, IMAGE_OPEN, "open.gif");
  386.             }
  387.             else
  388.             {
  389.                 elt.style.display = "none";
  390.                 d2himage(img, IMAGE_CLOSE, "closed.gif");
  391.             }
  392.         }
  393.     }
  394. }
  395.  
  396. // Sets a specified relative URL of image to specified HTML element
  397. function d2himage(element, image, def)
  398. {
  399.     if (element != null)
  400.     {
  401.         // Sets the default image if open image is not initialized
  402.         if (image.substring(0, 2) == "%O")
  403.             image = def;
  404.  
  405.         // Sets the default image if close image is not initialized
  406.         else if (image.substring(0, 2) == "%C")
  407.             image = def;
  408.  
  409.         // Hide element if image is missing
  410.         if (image == "")
  411.             element.style.visibility = "hidden";
  412.  
  413.         // Sets the specified image to element and displays it
  414.         else
  415.         {
  416.             element.src = d2hGetRelativePath(element.document, image);
  417.             element.style.visibility = "visible";
  418.         }    
  419.     }
  420. }
  421.  
  422. function d2hswitchpane(id)
  423. {
  424.     var sel, unsel, selimg, unselimg;
  425.     var prefix = id.substring(0, 8);
  426.     if (prefix == "D2HIndex")
  427.     {
  428.         sel = document.all("D2HIndex");
  429.         unsel = document.all("D2HContents");
  430.         selimg = INDEX_SELECTED;
  431.         unselimg = CONTENTS_UNSELECTED;
  432.     }
  433.     else if (prefix == "D2HConte")
  434.     {
  435.         sel = document.all("D2HContents");
  436.         unsel = document.all("D2HIndex");
  437.         selimg = CONTENTS_SELECTED;
  438.         unselimg = INDEX_UNSELECTED;
  439.     }
  440.  
  441.     if (sel != null)
  442.     {
  443.         sel.className = sel.id + "Selected";
  444.         var selimgelm = document.all(sel.id + "Image");
  445.         d2himage(selimgelm, selimg, "");
  446.     }
  447.  
  448.     if (unsel != null)
  449.     {
  450.         unsel.className = unsel.id + "Unselected";
  451.         var unselimgelm = document.all(unsel.id + "Image");
  452.         d2himage(unselimgelm, unselimg, "");
  453.     }
  454. }
  455.  
  456. function d2hactivepane()
  457. {
  458.     var id = "D2HContents";
  459.     var frms = window.parent.frames;
  460.     if (frms.length < 2)
  461.         return id;
  462.  
  463.     var frm = frms("left");
  464.     if (frm == null)
  465.         return id;
  466.  
  467.     var body = frm.document.body;
  468.     if (body != null)        
  469.         id = body.id;
  470.  
  471.     return id;                
  472. }
  473.  
  474. function d2hnsresize()
  475. {
  476.     if (d2hie())
  477.     {
  478.         dhtml_nonscrolling_resize();
  479.         var id = d2hactivepane();
  480.         d2hswitchpane(id);
  481.     }
  482. }
  483.  
  484. function d2h_before_print()
  485. {
  486.     document.body.scroll = "yes";
  487.     var oText = document.all.item("nstext");
  488.     if (oText != null)
  489.     {
  490.         oText.style.overflow = "visible";
  491.         oText.style.width = "100%";
  492.     }
  493.     var nav = document.all["ienav"];
  494.     if (nav != null)
  495.         nav.style.display = "none";
  496.     var oBanner = document.all.item("nsbanner");
  497.     if (oBanner != null)
  498.     {
  499.         oBanner.style.borderBottom = "0px";
  500.         oBanner.style.margin = "0px 0px 0px 0px";
  501.         oBanner.style.width = "100%";
  502.     }
  503. }
  504.  
  505. function d2h_after_print()
  506. {
  507.     document.location.reload();
  508. }
  509.  
  510. function d2h_set_popup_html(doc)
  511. {
  512.     doc.body.innerHTML = document.body.innerHTML;
  513.     var frame = doc.all("popupFrame");
  514.     if (frame != null)
  515.         frame.removeNode(true);
  516.     var nst = doc.all["nstext"];
  517.     if (nst != null)
  518.     {
  519.         nst.style.paddingTop = "0px";
  520.         nst.style.paddingLeft = "10px";
  521.         nst.style.removeAttribute("top", false);
  522.         nst.style.removeAttribute("width", false);
  523.         nst.style.removeAttribute("height", false);
  524.     }
  525.     var count = doc.all.length;
  526.     var elt, i;
  527.     //need to reset onclick event to prevent script error
  528.     //because scripts don't work when body is copied from document to frame
  529.     for (i = 0; i < count; i++)
  530.     {
  531.         elt = doc.all.item(i);
  532.         if ((elt.tagName == "A") || (elt.tagName == "a"))
  533.             elt.onclick = "";
  534.     }
  535. }
  536.  
  537. function d2h_hide_unused_elements(doc)
  538. {
  539.     var title = doc.all["TitleRow"];
  540.     if (title != null)
  541.         title.style.display = "none";
  542.     var nsb = doc.all["nsbanner"];
  543.     if (nsb != null)
  544.         nsb.style.display = "none";
  545.  
  546.     var count = doc.all.length;
  547.     var show = false, inTopic = false, id, elt, i;
  548.     for (i = 0; i < count; i++)
  549.     {
  550.         elt = doc.all.item(i);
  551.         var id = elt.id;
  552.         if (!inTopic && (id.length > 10) && (id.substring(0, 10) == "_D2HTopic_"))
  553.             inTopic = true;
  554.         if (elt.className == "_D2HAnchor")
  555.             show = (elt.name == ANCHOR);
  556.                    if (inTopic && !show)
  557.             elt.style.display = "none";
  558.     }
  559. }
  560.  
  561. function d2hGetRelativePath(doc, path)
  562. {
  563.     if (path.length >= 0)
  564.     {
  565.         var relPart = doc.body.getAttribute("relPart");
  566.         if (relPart == null)
  567.             relPart = "";
  568.         return relPart  + path;
  569.     }
  570.     else
  571.         return "";
  572. }
  573.  
  574. function d2hHideInline(elem)
  575. {
  576.     if (elem != null)
  577.     {
  578.         elem.style.visibility = "hidden";
  579.         elem.style.position = "absolute";
  580.         if (typeof elem.style.display != "undefined")
  581.             elem.style.display = "none";
  582.     }
  583. }
  584.  
  585. function d2hShowInline(elem)
  586. {
  587.     if (elem != null)
  588.     {
  589.         elem.style.visibility = "";
  590.         elem.style.position = "";
  591.         if (typeof elem.style.display != "undefined")
  592.             elem.style.display = "";
  593.     }
  594. }
  595.  
  596. function d2hInitInlineDropdown(elemId)
  597. {
  598.     var elem = getElemById(document, elemId);
  599.     d2hHideInline(elem);
  600. }
  601.  
  602. function d2hInitInlineExpand(elemId)
  603. {
  604.     var elem = getElemById(document, elemId);
  605.     d2hHideInline(elem);
  606. }
  607.  
  608. function d2hInitInlinePopup(elemId)
  609. {
  610.     var elem = getElemById(document, elemId);
  611.     if (elem != null)
  612.     {
  613.         d2hHideInline(elem);
  614.         elem.style.backgroundColor = POPUP_COLOR;
  615.         elem.style.backgroundImage = "url('" + d2hGetRelativePath(document, POPUP_IMAGE) + "')";
  616.         elem.style.backgroundRepeat = POPUP_REPEAT;
  617.         elem.style.border = "1px solid #cccccc";
  618.     }
  619. }
  620.  
  621. function d2hInlineExpand(evt, elemId)
  622. {
  623.     var elem = getElemById(document, elemId);
  624.     if (elem != null)
  625.     {
  626.         if (elem.style.visibility == "hidden")
  627.             d2hShowInline(elem);
  628.         else
  629.             d2hHideInline(elem);
  630.     }
  631.     return false;
  632. }
  633.  
  634. function d2hInlineDropdown(evt, elemId)
  635. {
  636.     var elem = getElemById(document, elemId);
  637.     if (elem != null)
  638.     {
  639.         if (elem.style.visibility == "hidden")
  640.             d2hShowInline(elem);
  641.         else
  642.             d2hHideInline(elem);
  643.     }
  644.     return false;
  645. }
  646.  
  647. function getElemById(doc, id)
  648. {
  649.     if (typeof doc.all != "undefined")
  650.         return doc.all(id);
  651.     else
  652.         return doc.getElementById(id);
  653. }
  654.  
  655. function d2hInlinePopup(evt, elemId)
  656. {
  657.     var elem = getElemById(document, elemId);
  658.     if (elem != null)
  659.     {
  660.         if (elem.style.visibility == "hidden")
  661.         {
  662.             if (d2hNeedSendToBody(elem))
  663.                 d2hSend2Body(elem);
  664.             if (typeof elem.style.display != "undefined")
  665.                 elem.style.display = "";
  666.             elem.style.width = "auto";
  667.             elem.style.height = "auto";
  668.             var pt = d2hGetInlinePosition(evt);
  669.             elem.style.visibility = "visible";
  670.             setInlinePopup2Pos(elem, pt.x, pt.y);
  671.             _d2hInlinePopup = elem;
  672.         }
  673.         else
  674.         {
  675.             d2hHideInline(elem);
  676.             elem.style.left = 0;
  677.             elem.style.top = 0;
  678.         }
  679.     }
  680.     return false;
  681. }
  682.  
  683. function setInlinePopup2Pos(popupElem, x, y)
  684. {
  685.     var nstext = getElemById(document, "nstext");
  686.     if (nstext == null)
  687.         nstext = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
  688.     d2hStandardizePopupMargin(popupElem);
  689.     var w_width = nstext.clientWidth ? nstext.clientWidth + nstext.scrollLeft : window.innerWidth + window.pageXOffset;
  690.     var w_height = nstext.clientHeight ? nstext.clientHeight + nstext.scrollTop : window.innerHeight + window.pageYOffset;
  691.     popupElem.style.width = "auto";
  692.     popupElem.style.height = "auto";
  693.     var textWidth = popupElem.offsetWidth;
  694.     var w = (w_width > 300)? w_width * 0.6: w_width;
  695.     if (textWidth > w)
  696.         textWidth = w;
  697.     popupElem.style.width = textWidth + "px";
  698.     var t_width = popupElem.offsetWidth;
  699.     var t_height = popupElem.offsetHeight;
  700.     textWidth = Math.sqrt(16*t_width*t_height/9);
  701.     popupElem.style.width = Math.round(textWidth) + "px";
  702.     t_width = popupElem.offsetWidth;
  703.     t_height = popupElem.offsetHeight;
  704.     popupElem.style.left = x + 8 + "px";
  705.     popupElem.style.top = y + 8 + "px";
  706.     var x_body_bottom = (document.body.clientWidth ? document.body.clientWidth : window.innerWidth) + document.body.scrollLeft;
  707.     var y_body_bottom = (document.body.clientHeight ? document.body.clientHeight : window.innerHeight) + document.body.scrollTop;
  708.     if (x + t_width > x_body_bottom)
  709.         popupElem.style.left = x_body_bottom - t_width + "px";
  710.     if (y + t_height > y_body_bottom)
  711.         popupElem.style.top = y_body_bottom - t_height + "px";
  712. }
  713.  
  714. function d2hIsTopicTitle(elem)
  715. {
  716.     if (elem.nodeType != 1)
  717.         return false;
  718.     var tagName = elem.tagName;
  719.     tagName = tagName.substring(0, 1).toLowerCase();
  720.     if (tagName == "h" || tagName == "p")
  721.         return true;
  722.     return false;
  723. }
  724.  
  725. function d2hTraverseElements(elem, func)
  726. {
  727.     func(elem);
  728.     var c = elem.firstChild;
  729.     while (c != null)
  730.     {
  731.         if (c.nodeType == 1)
  732.         {
  733.             func(c);
  734.             d2hTraverseElements(c, func);
  735.         }
  736.         c = c.nextSibling;
  737.     }
  738. }
  739.  
  740. function d2hSetZeroMargin(elem)
  741. {
  742.     elem.style.margin = "0pt";
  743.     elem.style.padding = "0pt";
  744. }
  745.  
  746. function d2hGetFirstChildElement(parent)
  747. {
  748.     var c = parent.firstChild;
  749.     while (c != null && c.nodeType != 1)
  750.         c = c.nextSibling;
  751.     if (c != null && c.nodeType == 1)
  752.         return c;
  753.     return null;
  754. }
  755.  
  756. function d2hStandardizePopupMargin(elem, marginpading2zeroElem, ienav)
  757. {   
  758.     elem.style.margin = "0pt";
  759.     elem.style.padding = "6pt";
  760.     var h = null;
  761.     var contents;
  762.     if (typeof marginpading2zeroElem != "undefined" && marginpading2zeroElem != null)
  763.     {
  764.         d2hSetZeroMargin(marginpading2zeroElem);
  765.         contents = marginpading2zeroElem;
  766.         if (typeof ienav != "undefined" && ienav != null)
  767.         {
  768.             ienav.className = "";
  769.             d2hTraverseElements(ienav, d2hSetZeroMargin);
  770.         }
  771.     }
  772.     else
  773.         contents = elem;
  774.     if (contents != null)
  775.         h = d2hGetFirstChildElement(contents);
  776.     if (h != null)
  777.     {
  778.         var tagName = h.tagName.toLowerCase();
  779.         if (tagName == "div")
  780.         {
  781.             d2hSetZeroMargin(h);
  782.             h = d2hGetFirstChildElement(h);
  783.         }
  784.         if (h != null && d2hIsTopicTitle(h))
  785.             d2hSetZeroMargin(h);
  786.     }
  787. }
  788.  
  789. function d2hGetParentElement(elem)
  790. {
  791.     var parent = null;
  792.     if (typeof elem != "undefined" && elem != null)
  793.     {
  794.         if (typeof elem.parentElement != "undefined")
  795.             parent = elem.parentElement;
  796.         else
  797.         {
  798.             parent = elem.parentNode;
  799.             if (parent != null && parent.nodeType != 1)
  800.             {
  801.                 parent = parent.parentNode;
  802.                 if (parent != null && parent.nodeType != 1)
  803.                     parent = null;
  804.             }
  805.         }
  806.     }
  807.     return parent;
  808. }
  809.  
  810. function d2hShowTopicTitleInPopup(doc)
  811. {
  812.     var nav = getElemById(doc, "nsbanner");
  813.     if (nav == null)
  814.         return;
  815.     var title = getElemById(doc, "_d2hTitleNavigator");
  816.     if (title == null)
  817.     {
  818.         nav.style.display = "none";
  819.         return;
  820.     }
  821.     var parent = d2hGetParentElement(nav);
  822.     if (parent == null)
  823.         return;
  824.     var objTitle = null;
  825.     if (typeof title.removeNode != "undefined")
  826.         objTitle = title.removeNode(true);
  827.     else
  828.         objTitle = title.cloneNode(true);
  829.     parent.replaceChild(objTitle, nav);
  830. }
  831.  
  832. function d2hNeedSendToBody(elem)
  833. {
  834.     var p = d2hGetParentElement(elem);
  835.     return !(p == null || p == document.body);
  836. }
  837.  
  838. function d2hMoveToEnd(elem, newParent)
  839. {
  840.     var obj = null;
  841.     if (typeof elem.removeNode != "undefined")
  842.         obj = elem.removeNode(true);
  843.     else
  844.     {
  845.         var parent = d2hGetParentElement(elem);
  846.         obj = parent.removeChild(elem);
  847.     }
  848.     newParent.appendChild(obj);
  849. }
  850.  
  851. function d2hSend2Body(elem)
  852. {
  853.     var body = document.body;
  854.     d2hMoveToEnd(elem, body);
  855. }
  856.  
  857. function point(x, y)
  858. {
  859.     this.x = x;
  860.     this.y = y;
  861. }
  862.  
  863. function d2hGetInlinePosition(evt)
  864. {
  865.     var pt = new point(evt.clientX + document.body.scrollLeft, evt.clientY + document.body.scrollTop);
  866.     return pt;
  867. }
  868.  
  869. function d2hRegisterEventHandler(obj, altObj, eventName, handler)
  870. {
  871.     var o = obj;
  872.     var oldHandler = o[eventName.toLowerCase()];
  873.     if (typeof oldHandler == "undefined" || oldHandler == null)
  874.     {
  875.         o = altObj;
  876.         oldHandler = o[eventName.toLowerCase()];
  877.     }
  878.     if (typeof oldHandler == "undefined" || oldHandler == null)
  879.     {
  880.         if (typeof document.scripts != "undefined")
  881.         {
  882.             var objName = typeof obj.open != "undefined" ? "window" : obj.tagName.toLowerCase();
  883.             var altName = typeof altObj.open != "undefined" ? "window" : altObj.tagName.toLowerCase();
  884.             for (var i = 0; i < document.scripts.length; i++) 
  885.             {
  886.                 var script = document.scripts[i];
  887.                 if ((script.htmlFor == obj.id || script.htmlFor == objName || script.htmlFor == altObj.id || script.htmlFor == altName) && script.event == eventName)
  888.                 {
  889.                     oldHandler = script.innerHTML;
  890.                     break;
  891.                 }
  892.             }
  893.         }
  894.     }
  895.     else
  896.     {
  897.             var defFunc = oldHandler.toString();
  898.             var beg = defFunc.indexOf('{');
  899.             var end = defFunc.lastIndexOf('}');
  900.             if (beg > 0 || end > beg)
  901.                 oldHandler = defFunc.substring(beg + 1, end - 1);
  902.     }
  903.     if (oldHandler && oldHandler.indexOf(handler) > -1)
  904.         return;
  905.     var newHandler = oldHandler;
  906.     if (oldHandler == null || newHandler.length == 0)
  907.         newHandler = handler;
  908.     else
  909.         newHandler += "; " + handler;
  910.     o[eventName.toLowerCase()] = new Function("event", newHandler);
  911. }
  912.  
  913. function d2hInitMainThemeHandlers()
  914. {
  915.     d2hRegisterEventHandler(window, document.body, "onload", "d2hnsresize();");
  916.     d2hRegisterEventHandler(window, document.body, "onmousedown", "d2hpopup();");
  917. }
  918.  
  919. function d2hInitSecThemeHandlers()
  920. {
  921.     d2hRegisterEventHandler(window, document.body, "onload", "d2hload();");
  922.     d2hRegisterEventHandler(window, document.body, "onmousedown", "d2hpopup();");
  923. }
  924.  
  925. function d2hElementInContainer(elem, container)
  926. {
  927.     do
  928.     {
  929.         if (elem == container)
  930.             return true;
  931.     }
  932.     while ((elem = d2hGetParentElement(elem)) != null)
  933.     return false;
  934. }
  935.  
  936. function d2hHideBreadcrumbs(doc)
  937. {
  938.     var breadcrumbs = getElemById(doc, "d2h_breadcrumbs");
  939.     if (breadcrumbs != null)
  940.         breadcrumbs.style.display = "none";
  941. }
  942.